summaryrefslogtreecommitdiff
path: root/app/[lng]/test/table-v2/columns.tsx
blob: 703e9fd8c83c125f730ebc63df2086c7f69e50ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"use client";

import { ColumnDef } from "@tanstack/react-table";
import { Badge } from "@/components/ui/badge";
import { TestProduct } from "@/db/schema/test-table-v2";
import { OrderWithDetails } from "./column-defs";

// === Product Columns (Pattern 1, 2) ===
// meta.serverGroupable: 서버 사이드 GROUP BY 지원 여부

export const productColumns: ColumnDef<TestProduct>[] = [
  {
    accessorKey: "id",
    header: "ID",
    size: 60,
    enableGrouping: false, // 클라이언트 그룹핑도 비활성화
    meta: { serverGroupable: false },
  },
  {
    accessorKey: "sku",
    header: "SKU",
    size: 100,
    enableGrouping: false,
    meta: { serverGroupable: false },
  },
  {
    accessorKey: "name",
    header: "Product Name",
    size: 200,
    enableGrouping: false,
    meta: { serverGroupable: false },
  },
  {
    accessorKey: "category",
    header: "Category",
    size: 120,
    enableGrouping: true, // ✅ 그룹핑 가능
    meta: { serverGroupable: true },
    cell: ({ getValue }) => {
      const category = getValue() as string;
      return <Badge variant="outline">{category}</Badge>;
    },
  },
  {
    accessorKey: "price",
    header: "Price",
    size: 100,
    enableGrouping: false,
    meta: { serverGroupable: false },
    cell: ({ getValue }) => {
      const price = parseFloat(getValue() as string);
      return new Intl.NumberFormat("en-US", {
        style: "currency",
        currency: "USD",
      }).format(price);
    },
  },
  {
    accessorKey: "stock",
    header: "Stock",
    size: 80,
    enableGrouping: false,
    meta: { serverGroupable: false },
    cell: ({ getValue }) => {
      const stock = getValue() as number;
      return (
        <span className={stock < 10 ? "text-red-500 font-medium" : ""}>
          {stock}
        </span>
      );
    },
  },
  {
    accessorKey: "status",
    header: "Status",
    size: 110,
    enableGrouping: true, // ✅ 그룹핑 가능
    meta: { serverGroupable: true },
    cell: ({ getValue }) => {
      const status = getValue() as string;
      const variants: Record<string, "default" | "secondary" | "destructive"> = {
        active: "default",
        inactive: "secondary",
        discontinued: "destructive",
      };
      return <Badge variant={variants[status] || "secondary"}>{status}</Badge>;
    },
  },
  {
    accessorKey: "isNew",
    header: "New",
    size: 60,
    enableGrouping: true, // ✅ 그룹핑 가능
    meta: { serverGroupable: true },
    cell: ({ getValue }) => {
      const isNew = getValue() as boolean;
      return isNew ? <Badge className="bg-emerald-500">NEW</Badge> : null;
    },
  },
  {
    accessorKey: "createdAt",
    header: "Created",
    size: 110,
    enableGrouping: false,
    meta: { serverGroupable: false },
    cell: ({ getValue }) => {
      const date = getValue() as Date;
      return date ? new Date(date).toLocaleDateString() : "-";
    },
  },
];

// === Order Columns with joined data (Pattern 3 - Custom Service) ===

export const orderColumns: ColumnDef<OrderWithDetails>[] = [
  {
    accessorKey: "id",
    header: "ID",
    size: 60,
  },
  {
    accessorKey: "orderNumber",
    header: "Order #",
    size: 140,
    cell: ({ getValue }) => (
      <span className="font-mono text-xs">{getValue() as string}</span>
    ),
  },
  {
    accessorKey: "customerName",
    header: "Customer",
    size: 150,
  },
  {
    accessorKey: "customerTier",
    header: "Tier",
    size: 90,
    cell: ({ getValue }) => {
      const tier = getValue() as string;
      if (!tier) return "-";
      const colors: Record<string, string> = {
        standard: "bg-gray-500",
        premium: "bg-blue-500",
        vip: "bg-amber-500",
      };
      return (
        <Badge className={colors[tier] || "bg-gray-500"}>
          {tier.toUpperCase()}
        </Badge>
      );
    },
  },
  {
    accessorKey: "productName",
    header: "Product",
    size: 180,
  },
  {
    accessorKey: "quantity",
    header: "Qty",
    size: 60,
  },
  {
    accessorKey: "totalAmount",
    header: "Total",
    size: 100,
    cell: ({ getValue }) => {
      const amount = parseFloat(getValue() as string);
      return new Intl.NumberFormat("en-US", {
        style: "currency",
        currency: "USD",
      }).format(amount);
    },
  },
  {
    accessorKey: "status",
    header: "Status",
    size: 110,
    cell: ({ getValue }) => {
      const status = getValue() as string;
      const variants: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
        pending: "outline",
        processing: "secondary",
        shipped: "default",
        delivered: "default",
        cancelled: "destructive",
      };
      const colors: Record<string, string> = {
        delivered: "bg-emerald-500",
        shipped: "bg-blue-500",
      };
      return (
        <Badge 
          variant={variants[status] || "secondary"}
          className={colors[status] || ""}
        >
          {status}
        </Badge>
      );
    },
  },
  {
    accessorKey: "orderedAt",
    header: "Order Date",
    size: 110,
    cell: ({ getValue }) => {
      const date = getValue() as Date;
      return date ? new Date(date).toLocaleDateString() : "-";
    },
  },
];